#!/bin/bash
[ $# -eq 0 ] && { echo "Usage: $0 WORD LANG"; exit 1; }

word=$1
lang=$2

# Test Parameters
statistic="--stat ll --stat_rank 500"
remove=15
window=2

expr_path=`pwd`

feature=bi
context=o2
space=vector
clmethod=direct
cluststop=pk2

	WORD=$word
	echo $WORD
	WORD_DIR=$expr_path/$WORD
	
	mkdir -p $WORD_DIR

	cd $WORD_DIR
		
		# PREPARE DATA
		# Remove all $WORD_DIR content
		#echo "Removing all data inside $WORD_DIR "
		#rm -r $WORD_DIR/*

		# Copy Regexs folder into $WORD_DIR
		#cp -r ../Regexs .

		echo "Preparing data for experiment execution"
		# Select instances of WORD and tag corpus with <head>$WORD</head>
		#$expr_path/myscripts/tagWord.sh $WORD $expr_path/$corpus tagged_data.txt

		# Convert plain text to sval2 format
		#text2sval.pl tagged_data.txt > $WORD-corpus.xml
		#rm tagged_data.txt

		# divide corpus into training and test parts	
		#preprocess.pl --token Regexs/token.regex --removeNotToken --split 95 $WORD-corpus.xml

		# Create the target.regex
		#maketarget.pl -head LEXELT-test.xml
		#mv target.regex Regexs/target.regex
		
		#remove unused files
		rm LEXELT-test.xml.* LEXELT-test.count
		rm LEXELT-training.xml

		# EXECUTE TEST
		prefix=$WORD-$lang
		resultsFolder=Results-$prefix.$feature.$context.$clmethod.$cluststop
		testfile=$WORD_DIR/LEXELT-test.xml
		trainfile=$WORD_DIR/LEXELT-training.count
		stopfile=$WORD_DIR/Regexs/stoplist-nsp.regex
		
		echo " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
	    echo "                    PROCESSING $resultsFolder"
		echo " %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "

		rm -r $resultsFolder
		mkdir -p $resultsFolder
		cd $resultsFolder

			echo " ******************************************************** "
			echo "Running with following parameters -"
			echo "--feature = $feature"
			echo "--context = $context"
			echo "--space = $space"
			echo "--clmethod = $clmethod"
			echo "--cluststop = $cluststop"

			echo " -------------------------------------------------------- "
			echo " Results in Directory: $resultsFolder"
			echo " -------------------------------------------------------- "

			    echo " discriminate.pl --showargs --verbose --eval --space $space --clmethod $clmethod --token $WORD_DIR/Regexs/token.regex --target $WORD_DIR/Regexs/target.regex --prefix $prefix --context $context --feature $feature --remove $remove --window $window --stop $stopfile --cluststop $cluststop $statistic --training $trainfile $testfile"
			  
			    discriminate.pl --showargs --verbose --eval --space $space --clmethod $clmethod --token $WORD_DIR/Regexs/token.regex --target $WORD_DIR/Regexs/target.regex --prefix $prefix --context $context --feature $feature --remove $remove --window $window --stop $stopfile --cluststop $cluststop $statistic --training $trainfile $testfile
			    echo " ******************************************************** "
		cd ..
	cd ..	